home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1996 June / macformat-038.iso / Shareware in MacFormat / Creator Changer 2.5 / Code & Resource / Creator Changer.dialog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-20  |  24.5 KB  |  852 lines  |  [TEXT/KAHL]

  1. /**********************************************************************
  2.  *    This file contains the bulk of the program.  All of the dialog box
  3.  *    stuff is performed in this file.
  4.  **********************************************************************/
  5.  
  6. #include "Creator Changer.h"
  7. #include "Creator Changer.dialog.h"
  8. #include "GetFileIcon.h"
  9.  
  10.  
  11. /**********************************************************************
  12.  *    Function Open_DLOG(), this function is a general function for 
  13.  *    opening all of the Dialog boxes in the program.
  14.  **********************************************************************/
  15.  
  16. void Open_DLOG(DialogPtr *the_dialog, short ID, OSType the_type, short DLOG_ID, short num, Ptr storage, AEDescList *the_files, long num_of_files)
  17.     {
  18.     
  19.     short                item_hit, the_item;
  20.     Handle                menu_handle;
  21.     Rect                the_rect;
  22.     Boolean            done_with_dialog;
  23.     ModalFilterUPP        My_Dialog_FilterUPP;
  24.     GrafPtr                old_port;
  25.     File_Union            temp;
  26.     
  27.     GetPort(&old_port);
  28.     done_with_dialog=FALSE;
  29.     *the_dialog=GetNewDialog(DLOG_ID, storage, IN_FRONT);
  30.     
  31.     Make_Pop_Up_Menu(ID, the_type, num);
  32.     GetDItem(*the_dialog, POP_UP_MENU, &the_item, &menu_handle, &the_rect);
  33.     (**(ControlHandle)menu_handle).contrlValue=0;
  34.     Draw1Control((ControlHandle)menu_handle);
  35.     
  36.     ShowWindow(*the_dialog);
  37.     if(!Multiple_Files && *the_dialog==Chng_Dialog)
  38.         {
  39.         Set_Type_Text(&F_Type, File_Info.fdType);
  40.         Set_Type_Text(&C_Type, File_Info.fdCreator);
  41.         }
  42.     
  43.     My_Dialog_FilterUPP=NewModalFilterProc(My_Dialog_Filter);
  44.     
  45.     while(!done_with_dialog)
  46.         {
  47.         ModalDialog(My_Dialog_FilterUPP, &item_hit);
  48.         if(*the_dialog==Chng_Dialog)        done_with_dialog=Change_Dialog_Switch(*the_dialog, item_hit, menu_handle, the_files, num_of_files);
  49.         else if(*the_dialog==Edit_Dialog)    done_with_dialog=  Edit_Dialog_Switch(*the_dialog, item_hit, menu_handle);
  50.         else if(*the_dialog==Auto_Dialog)    done_with_dialog=  Auto_Dialog_Switch(*the_dialog, item_hit, menu_handle);
  51.         else done_with_dialog=TRUE;
  52.         }
  53.     
  54.     CloseDialog(*the_dialog);
  55.     SetPort(old_port);
  56.     
  57.     }
  58.  
  59.  
  60.  
  61. /**********************************************************************
  62.  *    Function Change_Dialog_Switch(), this function decides where events
  63.  *    in the Chng_Dialog box should go.
  64.  **********************************************************************/
  65.  
  66. Boolean Change_Dialog_Switch(DialogPtr the_dialog, short item_hit, Handle menu_handle, AEDescList *the_files, long num_of_files)
  67.     {
  68.     switch(item_hit)
  69.         {
  70.         case CHNG_OK:
  71.             return(Handle_OK_Change(the_dialog, CHNG_CREATOR, CHNG_FILE, the_files, num_of_files));
  72.             break;
  73.         case POP_UP_MENU:
  74.             Handle_pt_Pop_Up_Menu(menu_handle, the_dialog, CHNG_CREATOR, CHNG_FILE, NO);
  75.             break;
  76.         case CHNG_CANCEL:
  77.             return(TRUE);
  78.             break;
  79.         case CHNG_MKLK:
  80.             Handle_Make_Like(the_dialog, CHNG_FILE, CHNG_CREATOR, NIL_PTR);
  81.             break;
  82.         case CHNG_CRNT_CREATOR:
  83.             if(!Multiple_Files) Set_DLOG_Text_Item(the_dialog, CHNG_CREATOR, C_Type.TEXT);
  84.             break;
  85.         case CHNG_CRNT_TYPE:
  86.             if(!Multiple_Files) Set_DLOG_Text_Item(the_dialog, CHNG_FILE, F_Type.TEXT);
  87.             break;
  88.         defualt:
  89.             break;
  90.         }
  91.     return(FALSE);
  92.     }
  93.  
  94.  
  95. /**********************************************************************
  96.  *    Function Edit_Dialog_Switch(), this function decides where events
  97.  *    in the Edit_Dialog box should go.
  98.  **********************************************************************/
  99.  
  100. Boolean Edit_Dialog_Switch(DialogPtr the_dialog, short item_hit, Handle menu_handle)
  101.     {
  102.     switch(item_hit)
  103.         {
  104.         case EDIT_CLOSE:
  105.             return(TRUE);
  106.             break;
  107.         case EDIT_ADD:
  108.             Handle_Add_Pref_Item(the_dialog, EDIT_CREATOR, EDIT_FILE, EDIT_DESCR);
  109.             Draw1Control((ControlHandle)menu_handle);
  110.             break;
  111.         case EDIT_DELETE:
  112.             Handle_Delete_Pref_Item();
  113.             Draw1Control((ControlHandle)menu_handle);
  114.             break;
  115.         case POP_UP_MENU:
  116.             Handle_pt_Pop_Up_Menu(menu_handle, the_dialog, EDIT_CREATOR, EDIT_FILE, EDIT_DESCR);
  117.             break;
  118.         case EDIT_GET_FILE:
  119.             Handle_Make_Like(the_dialog, EDIT_FILE, EDIT_CREATOR, NIL_PTR);
  120.             break;
  121.         defualt:
  122.             break;
  123.         }
  124.     return(FALSE);
  125.     }
  126.  
  127.  
  128. /**********************************************************************
  129.  *    Function Auto_Dialog_Switch(), this function decides where events
  130.  *    in the Auto_Dialog box should go.
  131.  **********************************************************************/
  132.  
  133. Boolean Auto_Dialog_Switch(DialogPtr the_dialog, short item_hit, Handle menu_handle)
  134.     {
  135.     
  136.     global_prefs    **rsrc_handle;
  137.  
  138.     switch(item_hit)
  139.         {
  140.         case AUTO_ADD:
  141.             Handle_Add_Auto_Item(the_dialog, AUTO_FRM_TYPE, AUTO_CREATOR, AUTO_FILE);
  142.             break;
  143.         case AUTO_CLOSE:
  144.             return(TRUE);
  145.             break;
  146.         case AUTO_DELETE:
  147.             Handle_Delete_Auto_Item();
  148.             break;
  149.         case POP_UP_MENU:
  150.             Handle_ac_Pop_Up_Menu(menu_handle, the_dialog, AUTO_FRM_TYPE, AUTO_CREATOR, AUTO_FILE);
  151.             break;
  152.         case AUTO_DO:
  153.             UseResFile(CreatorChangerPref);
  154.                 rsrc_handle=(global_prefs **)GetResource(PREF_GL, 128);
  155.                 (**rsrc_handle).AutoChange=Handle_Check_item(the_dialog, AUTO_DO);;
  156.                 ChangedResource((Handle)rsrc_handle);
  157.                 UpdateResFile(CreatorChangerPref);
  158.             UseResFile(CreatorChangerApp);
  159.             break;
  160.         case AUTO_QUIT:
  161.             UseResFile(CreatorChangerPref);
  162.                 rsrc_handle=(global_prefs **)GetResource(PREF_GL, 128);
  163.                 (**rsrc_handle).DragQuit=Handle_Check_item(the_dialog, AUTO_QUIT);;
  164.                 ChangedResource((Handle)rsrc_handle);
  165.                 UpdateResFile(CreatorChangerPref);
  166.             UseResFile(CreatorChangerApp);
  167.         break;
  168.         case AUTO_GET_FILE:
  169.             Handle_Make_Like(the_dialog, AUTO_FILE, AUTO_CREATOR, AUTO_FRM_TYPE);
  170.         defualt:
  171.             break;
  172.         }
  173.     return(FALSE);
  174.     }
  175.  
  176.  
  177. /**********************************************************************
  178.  *    Function Handle_OK_Change(), this function calls the functions
  179.  *    which do the changing of the creator and file types.
  180.  **********************************************************************/
  181.  
  182. Boolean Handle_OK_Change(DialogPtr the_dialog, int creator, int file, AEDescList *the_files, long num_of_files)
  183.      {
  184.      
  185.      int             temp;
  186.      int    register    i;
  187.      AEKeyword        key_word;
  188.     DescType        the_type;
  189.     Size            the_size;
  190.      
  191.      temp=Check_Data(the_dialog, file, NO)+Check_Data(the_dialog, creator, NO);
  192.      
  193.     if(temp<TYPE_LEN)
  194.         {
  195.         for(i=1;i<=num_of_files;i++)
  196.             {
  197.             if(Multiple_Files)
  198.                 {
  199.                 AEGetNthPtr(the_files, i, typeFSS, &key_word, &the_type, &The_File_Spec, sizeof(The_File_Spec), &the_size);
  200.                 FSpGetFInfo(&The_File_Spec, &File_Info);
  201.                 }
  202.             Set_Long_Type(NIL_PTR, &File_Info.fdType,    the_dialog, file);
  203.             Set_Long_Type(NIL_PTR, &File_Info.fdCreator, the_dialog, creator);
  204.             FSpSetFInfo(&The_File_Spec, &File_Info);
  205.             }
  206.         Force_Finder_Update(&The_File_Spec);
  207.         if(Multiple_Files) AEDisposeDesc(the_files);
  208.         return(GOOD);
  209.         }
  210.     else
  211.         {
  212.         Do_Error(Types_Error_1, EMPTY_STR, Types_Error_2, EMPTY_STR);
  213.         return(BAD);
  214.         }
  215.     }
  216.  
  217.  
  218.  
  219. /**********************************************************************
  220.  *    Function Set_Long_Type(), this function sets the file type of the
  221.  *    specified file.  (converts a string in an edit field to an 
  222.  *    unsigned decimal equivalent, and then returns it).
  223.  **********************************************************************/
  224.  
  225. void Set_Long_Type(Str4 in_string, OSType *out_long,  DialogPtr the_dialog, int ID)
  226.     {
  227.     
  228.     File_Union    file_type;
  229.     Handle        item_handle;
  230.     short        item_type;
  231.     Rect        item_rect;
  232.     int            i;
  233.     
  234.     if(the_dialog!=NIL_PTR)
  235.         {
  236.         GetDItem(the_dialog, ID, &item_type, &item_handle, &item_rect);
  237.         GetIText(item_handle, in_string);
  238.         }
  239.         
  240.     for(i=0;i<=TYPE_LEN;i++) file_type.TEXT[i]=in_string[i+1];
  241.     
  242.     *out_long=file_type.LONG;
  243.     
  244.     }
  245.  
  246.  
  247.  
  248. /**********************************************************************
  249.  *    Function Handle_Make_Like(), this function picks a file to use as
  250.  *    a template.
  251.  **********************************************************************/
  252.  
  253. void Handle_Make_Like(DialogPtr the_dialog, short file, short creator, short from_file)
  254.     {
  255.     
  256.     File_Union    f_type, c_type;
  257.     FInfo        ml_file_info;
  258.     FSSpec        ml_file_spec;
  259.     
  260.     if(Pick_File(&ml_file_spec, &ml_file_info, FALSE))
  261.         {
  262.         Set_Type_Text(&f_type, ml_file_info.fdType);
  263.         Set_Type_Text(&c_type, ml_file_info.fdCreator);
  264.         
  265.         if(from_file) Set_DLOG_Text_Item(the_dialog, from_file, f_type.TEXT);
  266.         Set_DLOG_Text_Item(the_dialog, file,    f_type.TEXT);
  267.         Set_DLOG_Text_Item(the_dialog, creator, c_type.TEXT);
  268.         
  269.         if(the_dialog==Edit_Dialog) PT_Item_To_Edit=0;
  270.         }
  271.     
  272.     }
  273.  
  274.  
  275.  
  276. /**********************************************************************
  277.  *    Function Set_Type_Text(), this function sets the text for the file
  278.  *    and creator types given an usigned decimal file / creator type.
  279.  **********************************************************************/
  280.  
  281. void Set_Type_Text(File_Union *the_type, OSType the_long_type)
  282.     {
  283.     
  284.     File_Union    temp;
  285.     int            i;
  286.     
  287.     (*the_type).TEXT[0]=TYPE_LEN;
  288.     temp.LONG=the_long_type;
  289.     for(i=0;i<=TYPE_LEN;i++) (*the_type).TEXT[i+1]=temp.TEXT[i];
  290.     
  291.     }
  292.  
  293.  
  294.  
  295. /**********************************************************************
  296.  *    Function Handle_Add_Pref_Item(), this function actually does the adding
  297.  *    of the items to the preferences file.
  298.  **********************************************************************/
  299.  
  300. void Handle_Add_Pref_Item(DialogPtr the_dialog, int creator, int file, int description)
  301.     {
  302.     
  303.     pref_types    **rsrc_handle;
  304.     Handle        item_handle;
  305.     short        item_type;
  306.     Rect        item_rect;
  307.     Str4        file_type, creator_type;
  308.     Str32        description_type;
  309.     int            temp;
  310.     
  311.     temp=Check_Data(the_dialog, file, NO)+Check_Data(the_dialog, creator, NO)+Check_Data(the_dialog, description, YES);
  312.     
  313.     if(temp<TYPE_LEN)
  314.         {
  315.         UseResFile(CreatorChangerPref);
  316.             rsrc_handle=(pref_types **)NewHandle(sizeof(pref_types));
  317.         
  318.             GetDItem(the_dialog, description, &item_type, &item_handle, &item_rect);
  319.             GetIText(item_handle, description_type);
  320.             GetDItem(the_dialog, creator, &item_type, &item_handle, &item_rect);
  321.             GetIText(item_handle, creator_type);
  322.             GetDItem(the_dialog, file, &item_type, &item_handle, &item_rect);
  323.             GetIText(item_handle, file_type);
  324.         
  325.             p_Str_Copy(description_type, (**rsrc_handle).Description);
  326.             p_Str_Copy(creator_type, (**rsrc_handle).CreatorType);
  327.             p_Str_Copy(file_type, (**rsrc_handle).FileType);
  328.             
  329.             AddResource((Handle)rsrc_handle, PREF_PT, Num_pt==0 ? Strt_Rsrc : The_pt_Type[Num_pt]+1, description_type);
  330.             ChangedResource((Handle)rsrc_handle);
  331.             UpdateResFile(CreatorChangerPref);
  332.             Num_pt=CountResources(PREF_PT);
  333.             ReleaseResource((Handle)rsrc_handle);
  334.         UseResFile(CreatorChangerApp);
  335.         Make_Pop_Up_Menu(PREF_TYPES_ID, PREF_PT, Num_pt);
  336.         PT_Item_To_Edit=0;
  337.         }
  338.     else if(temp<=TYPE_LEN+TYPE_LEN+1)    Do_Error(Types_Error_1, EMPTY_STR, Types_Error_2, EMPTY_STR);
  339.     else if(temp==DESC_LEN+2)            Do_Error(Descr_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  340.     else                                Do_Error(Types_Error_1, Descr_Error, EMPTY_STR, EMPTY_STR);
  341.     
  342.     }
  343.  
  344.  
  345.  
  346. /**********************************************************************
  347.  *    Function Handle_Delete_Pref_Item(), this function actually does the
  348.  *    deleting of the item from the preferences file.
  349.  **********************************************************************/
  350.  
  351. void Handle_Delete_Pref_Item()
  352.     {
  353.     
  354.     pref_types    **rsrc_handle;
  355.     short        resource_number, i;
  356.     
  357.     if(PT_Item_To_Edit)
  358.         {
  359.         UseResFile(CreatorChangerPref);
  360.             resource_number=The_pt_Type[PT_Item_To_Edit];
  361.             rsrc_handle=(pref_types **)NewHandle(sizeof(pref_types));
  362.             rsrc_handle=(pref_types **)GetResource(PREF_PT, resource_number);
  363.             RmveResource((Handle)rsrc_handle);
  364.             ReleaseResource((Handle)rsrc_handle);
  365.             UpdateResFile(CreatorChangerPref);
  366.         
  367.             for(i=(resource_number+1);i<=The_pt_Type[Num_pt];i++)
  368.                 {
  369.                 rsrc_handle=(pref_types **)GetResource(PREF_PT, i);
  370.                 DetachResource((Handle)rsrc_handle);
  371.                 AddResource((Handle)rsrc_handle, PREF_PT, i-1, NIL_PTR);
  372.                 ChangedResource((Handle)rsrc_handle);
  373.                 ReleaseResource((Handle)rsrc_handle);
  374.                 
  375.                 rsrc_handle=(pref_types **)GetResource(PREF_PT, i);
  376.                 RmveResource((Handle)rsrc_handle);
  377.                 ChangedResource((Handle)rsrc_handle);
  378.                 ReleaseResource((Handle)rsrc_handle);
  379.                 }
  380.             
  381.             UpdateResFile(CreatorChangerPref);
  382.             Num_pt=CountResources(PREF_PT);
  383.         UseResFile(CreatorChangerApp);
  384.         Make_Pop_Up_Menu(PREF_TYPES_ID, PREF_PT, Num_pt);
  385.         PT_Item_To_Edit=0;
  386.         }
  387.     else Do_Error(Bad_Item_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  388.         
  389.     }
  390.  
  391.  
  392.  
  393. /**********************************************************************
  394.  *    Function Handle_Add_Auto_Item(), this function actually does the adding
  395.  *    of the items to the preferences file.
  396.  **********************************************************************/
  397.  
  398. void Handle_Add_Auto_Item(DialogPtr the_dialog, int from_file_id, int to_creator_id, int to_file_id)
  399.     {
  400.     
  401.     Handle                item_handle;
  402.     OSType                long_from_file;
  403.     short                item_type;
  404.     Rect                item_rect;
  405.     int                    temp;
  406.     auto_chng            **rsrc_handle;
  407.     Str4                from_file, to_creator, to_file, types[100];
  408.                 
  409.     temp=Check_Data(the_dialog, from_file_id, NO)+Check_Data(the_dialog, to_creator_id, NO)+Check_Data(the_dialog, to_file_id, NO);
  410.     
  411.     if(temp<TYPE_LEN)
  412.         {
  413.         Get_Types_From_Prefs(types);
  414.         Set_Long_Type(NIL_PTR, &long_from_file, the_dialog, from_file_id);
  415.         if(Check_File_Type(types, long_from_file))
  416.             {
  417.             ParamText(Bad_CF_Type_1, Bad_CF_Type_2, Bad_CF_Type_3, Bad_CF_Type_4);
  418.             Alert(ERROR_ALERT_ID, NIL_PTR);
  419.             }
  420.         else
  421.             {
  422.             GetDItem(the_dialog,  from_file_id, &item_type, &item_handle, &item_rect);
  423.             GetIText(item_handle, from_file);
  424.             GetDItem(the_dialog,  to_creator_id, &item_type, &item_handle, &item_rect);
  425.             GetIText(item_handle, to_creator);
  426.             GetDItem(the_dialog,  to_file_id, &item_type, &item_handle, &item_rect);
  427.             GetIText(item_handle, to_file);
  428.             
  429.             rsrc_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
  430.             p_Str_Copy(from_file,  (**rsrc_handle).FromFile);
  431.             p_Str_Copy(to_creator, (**rsrc_handle).ToCreator);
  432.             p_Str_Copy(to_file,    (**rsrc_handle).ToFile);
  433.             Make_ac_Name((**rsrc_handle).Name, from_file, to_creator, to_file);
  434.                 
  435.             UseResFile(CreatorChangerPref);
  436.                 AddResource((Handle)rsrc_handle, PREF_AC, Num_ac==0 ? Strt_Rsrc : The_ac_Type[Num_ac]+1, (**rsrc_handle).Name);
  437.                 ChangedResource((Handle)rsrc_handle);
  438.                 UpdateResFile(CreatorChangerPref);
  439.                 Num_ac=CountResources(PREF_AC);
  440.             UseResFile(CreatorChangerApp);
  441.             ReleaseResource((Handle)rsrc_handle);
  442.             }
  443.         Make_Pop_Up_Menu(AUTO_CHANGE_ID, PREF_AC, Num_ac);
  444.         AC_Item_To_Edit=0;
  445.         }
  446.     else Do_Error(Types_Error_1, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  447.     
  448.     }
  449.  
  450.  
  451.  
  452. /**********************************************************************
  453.  *    Function Make_ac_Name(), this function makes the name
  454.  *    which shows up in the pop-up menu for the auto change items.
  455.  **********************************************************************/
  456.  
  457. void Make_ac_Name(StringPtr name, StringPtr from_file, StringPtr to_creator, StringPtr to_file)
  458.     {
  459.     
  460.     register int i;
  461.     
  462.     name[0]=16;
  463.     for(i=1;i<=4;i++) name[i]=from_file[i];
  464.     name[5]='-';
  465.     name[6]='>';
  466.     for(i=7;i<=10;i++) name[i]=to_creator[i-6];
  467.     name[11]=',';
  468.     name[12]=' ';
  469.     for(i=13;i<=16;i++) name[i]=to_file[i-12];
  470.     
  471.     }
  472.  
  473.  
  474. /**********************************************************************
  475.  *    Function Handle_Delete_Auto_Item(), this function deletes items 
  476.  *    from the auto change item list.
  477.  **********************************************************************/
  478.  
  479. void Handle_Delete_Auto_Item(void)
  480.     {
  481.     
  482.     auto_chng    **rsrc_handle;
  483.     short        resource_number, i;
  484.     
  485.     if(AC_Item_To_Edit)
  486.         {
  487.         UseResFile(CreatorChangerPref);
  488.             resource_number=The_ac_Type[AC_Item_To_Edit];
  489.             
  490.             rsrc_handle=(auto_chng **)NewHandle(sizeof(auto_chng));
  491.             rsrc_handle=(auto_chng **)GetResource(PREF_AC, resource_number);
  492.             RmveResource((Handle)rsrc_handle);
  493.             ReleaseResource((Handle)rsrc_handle);
  494.             UpdateResFile(CreatorChangerPref);
  495.         
  496.             for(i=(resource_number+1);i<=The_ac_Type[Num_ac];i++)
  497.                 {
  498.                 rsrc_handle=(auto_chng **)GetResource(PREF_AC, i);
  499.                 DetachResource((Handle)rsrc_handle);
  500.                 AddResource((Handle)rsrc_handle, PREF_AC, i-1, NIL_PTR);
  501.                 ChangedResource((Handle)rsrc_handle);
  502.                 ReleaseResource((Handle)rsrc_handle);
  503.                 
  504.                 rsrc_handle=(auto_chng **)GetResource(PREF_AC, i);
  505.                 RmveResource((Handle)rsrc_handle);
  506.                 ChangedResource((Handle)rsrc_handle);
  507.                 ReleaseResource((Handle)rsrc_handle);
  508.                 }
  509.             
  510.             UpdateResFile(CreatorChangerPref);
  511.             Num_ac=CountResources(PREF_AC);
  512.         UseResFile(CreatorChangerApp);
  513.         Make_Pop_Up_Menu(AUTO_CHANGE_ID, PREF_AC, Num_ac);
  514.         AC_Item_To_Edit=0;
  515.         }
  516.     else Do_Error(Bad_Item_Error, EMPTY_STR, EMPTY_STR, EMPTY_STR);
  517.     
  518.     }
  519.  
  520.  
  521. /**********************************************************************
  522.  *    Function Handle_Check_item(), this function either checks or 
  523.  *    unchecks a check box item.
  524.  **********************************************************************/
  525.  
  526. Boolean Handle_Check_item(DialogPtr the_dialog, short dialog_item)
  527.     {
  528.     
  529.     short        the_item;
  530.     Handle        the_handle;
  531.     Rect        the_rect;
  532.     Boolean    value;
  533.     
  534.     GetDItem(the_dialog, dialog_item, &the_item, &the_handle, &the_rect);
  535.     value=GetCtlValue((ControlHandle)the_handle);
  536.     
  537.     if(value==TRUE)
  538.         {
  539.         SetCtlValue((ControlHandle)the_handle, FALSE);
  540.         return(FALSE);
  541.         }
  542.     else if(value==FALSE)
  543.         {
  544.         SetCtlValue((ControlHandle)the_handle, TRUE);
  545.         return(TRUE);
  546.         }
  547.     
  548.     }
  549.  
  550.  
  551. /**********************************************************************
  552.  *    Function Draw_Default_Border(), this function draws the border
  553.  *    around the item sent to it, that is within the specified dialog box
  554.  **********************************************************************/
  555.  
  556. void Draw_Border(DialogPtr the_dialog, short the_item, short is_default)
  557.     {
  558.     
  559.     Handle        the_handle;
  560.     short        the_type;
  561.     Rect        the_rect;
  562.     GrafPtr        old_port;
  563.     short        diameter;
  564.             
  565.     GetPort(&old_port);
  566.     SetPort(the_dialog);
  567.  
  568.     GetDItem(the_dialog, the_item, &the_type, &the_handle, &the_rect);
  569.  
  570.     if(is_default)
  571.         {
  572.         diameter=(the_rect.bottom-the_rect.top)/2+6;
  573.         if(diameter<16) diameter=16;
  574.         PenSize(3, 3);
  575.         InsetRect(&the_rect, -4, -4);
  576.         FrameRoundRect(&the_rect, diameter, diameter);
  577.         }
  578.     else
  579.         {
  580.         PenSize(1, 1);
  581.         FrameRect(&the_rect);
  582.         }
  583.     
  584.     SetPort(old_port);
  585.     
  586.     }
  587.  
  588.  
  589.  
  590. /**********************************************************************
  591.  *    Function My_Dialog_Filter(), this function handels if there was a 
  592.  *    particular key pressed in the dialog box, and if the dialog box was
  593.  *    moved at all.
  594.  **********************************************************************/
  595.  
  596. pascal Boolean My_Dialog_Filter(DialogPtr the_dialog, EventRecord *the_event, short *item_hit)
  597.     {
  598.     
  599.     Boolean    answer=FALSE;
  600.     
  601.     switch(the_event->what)
  602.         {
  603.         case updateEvt:
  604.             {
  605.             GrafPtr old_port;
  606.  
  607.             GetPort(&old_port);
  608.             SetPort(the_dialog);
  609.             
  610.             BeginUpdate(the_dialog);
  611.                 UpdtDialog(the_dialog, the_dialog->visRgn);
  612.                 if(the_dialog==Chng_Dialog)       Draw_Dialog(Chng_Dialog);
  613.                 else if(the_dialog==Edit_Dialog) Draw_Dialog(Edit_Dialog);
  614.                 else if(the_dialog==Auto_Dialog) Draw_Dialog(Auto_Dialog);
  615.             EndUpdate(the_dialog);
  616.             
  617.             SetPort(old_port);
  618.             answer=TRUE;
  619.             }
  620.             break;
  621.         case mouseDown:
  622.             {
  623.             WindowPtr        the_window;
  624.             RgnHandle        the_gray_rgn;
  625.             short            the_part;
  626.             static Point    where;
  627.  
  628.             where=the_event->where;
  629.             
  630.             the_part=FindWindow(where, &the_window);
  631.             if((the_part==inDrag) && (the_window==the_dialog))
  632.                 {
  633.                 the_gray_rgn=GetGrayRgn();
  634.                 DragWindow(the_window, the_event->where, &((**the_gray_rgn).rgnBBox));
  635.                 answer=TRUE;
  636.                 }
  637.             else GlobalToLocal(&where);
  638.             }
  639.             break;
  640.         case keyDown:
  641.             {
  642.             static char    key_pressed;
  643.             
  644.             key_pressed=the_event->message & charCodeMask;
  645.             
  646.             if(!(the_event->modifiers & cmdKey))
  647.                 {
  648.                 PT_Item_To_Edit=0;
  649.                 switch(key_pressed)
  650.                     {
  651.                     case Escape_Key:
  652.                         if(the_dialog==Chng_Dialog)          answer=Handle_Key_Pressed(the_dialog, CHNG_CANCEL, item_hit);
  653.                         else if(the_dialog==Edit_Dialog) answer=Handle_Key_Pressed(the_dialog, EDIT_CLOSE,  item_hit);
  654.                         else if(the_dialog==Auto_Dialog) answer=Handle_Key_Pressed(the_dialog, AUTO_CLOSE,  item_hit);
  655.                         break;
  656.                     case Return_Key:
  657.                     case Enter_Key:
  658.                         if(the_dialog==Chng_Dialog)          answer=Handle_Key_Pressed(the_dialog, CHNG_OK,    item_hit);
  659.                         else if(the_dialog==Edit_Dialog) answer=Handle_Key_Pressed(the_dialog, EDIT_CLOSE, item_hit);
  660.                         else if(the_dialog==Auto_Dialog) answer=Handle_Key_Pressed(the_dialog, AUTO_CLOSE, item_hit);
  661.                         break;
  662.                     }
  663.                 }
  664.             else
  665.                 {
  666.                 if(the_dialog==Chng_Dialog)
  667.                     switch(key_pressed)
  668.                         {
  669.                         case 'M':
  670.                         case 'm':
  671.                             answer=Handle_Key_Pressed(the_dialog, CHNG_MKLK, item_hit);
  672.                             break;
  673.                         case 'C':
  674.                         case 'c':
  675.                             answer=Handle_Key_Pressed(the_dialog, CHNG_CANCEL, item_hit);
  676.                             break;
  677.                         }
  678.                 else if(the_dialog==Edit_Dialog)
  679.                     switch(key_pressed)
  680.                         {
  681.                         case 'D':
  682.                         case 'd':
  683.                             answer=Handle_Key_Pressed(the_dialog, EDIT_DELETE, item_hit);
  684.                             break;
  685.                         case 'A':
  686.                         case 'a':
  687.                             answer=Handle_Key_Pressed(the_dialog, EDIT_ADD, item_hit);
  688.                             break;
  689.                         case 'G':
  690.                         case 'g':
  691.                             answer=Handle_Key_Pressed(the_dialog, EDIT_GET_FILE, item_hit);
  692.                             break;
  693.                         }
  694.                 else if(the_dialog==Auto_Dialog)
  695.                     switch(key_pressed)
  696.                         {
  697.                         case 'D':
  698.                         case 'd':
  699.                             answer=Handle_Key_Pressed(the_dialog, AUTO_DELETE, item_hit);
  700.                             break;
  701.                         case 'A':
  702.                         case 'a':
  703.                             answer=Handle_Key_Pressed(the_dialog, AUTO_ADD, item_hit);
  704.                             break;
  705.                         case 'C':
  706.                         case 'c':
  707.                             answer=Handle_Key_Pressed(the_dialog, AUTO_DO, item_hit);
  708.                             break;
  709.                         case 'Q':
  710.                         case 'q':
  711.                             answer=Handle_Key_Pressed(the_dialog, AUTO_QUIT, item_hit);
  712.                             break;
  713.                         case 'G':
  714.                         case 'g':
  715.                             answer=Handle_Key_Pressed(the_dialog, AUTO_GET_FILE, item_hit);
  716.                             break;
  717.                         }
  718.                 }
  719.             }
  720.             break;
  721.         }
  722.     return(answer);
  723.     }
  724.  
  725.  
  726.  
  727. /**********************************************************************
  728.  *    Function Handle_Key_Pressed(), this function handels what happens 
  729.  *    if a key is pressed.
  730.  **********************************************************************/
  731.  
  732. int Handle_Key_Pressed(DialogPtr the_dialog, int the_item, short *item_hit)
  733.     {
  734.     
  735.     short    item_type, item_value;
  736.     Handle    item_handle;
  737.     Rect    item_rect;
  738.     long    delay;
  739.                     
  740.     GetDItem(the_dialog, the_item, &item_type, &item_handle, &item_rect);
  741.     HiliteControl((ControlHandle)item_handle, 1);
  742.     Delay(DELAY, &delay);
  743.     HiliteControl((ControlHandle)item_handle, 0);
  744.     *item_hit=the_item;
  745.     return(TRUE);
  746.     
  747.     }
  748.  
  749.  
  750.  
  751. /**********************************************************************
  752.  *    Function Check_Data(), this function checks the type entered
  753.  *    by the user.  If there are more than 4 charachters than there is 
  754.  *    an error, and if there is no data entered in there is an error.
  755.  **********************************************************************/
  756.  
  757. int Check_Data(DialogPtr the_dialog, int ID, short is_desc)
  758.     {
  759.     
  760.     Str255        the_error;
  761.     Str32        item_text;
  762.     Handle        item_handle;
  763.     short        item_type;
  764.     Rect        item_rect;
  765.     int            len;
  766.     short        the_type_len;
  767.     
  768.     GetDItem(the_dialog, ID, &item_type, &item_handle, &item_rect);
  769.     GetIText(item_handle, item_text);
  770.     
  771.     len=item_text[0];
  772.     if(is_desc) the_type_len=DESC_LEN;
  773.     else the_type_len=TYPE_LEN;
  774.     if(len!=the_type_len && the_type_len==TYPE_LEN) return(TYPE_LEN);
  775.     else if((len>the_type_len && the_type_len==DESC_LEN) || len==0) return(DESC_LEN);
  776.     else return(GOOD);
  777.     
  778.     }
  779.  
  780.  
  781.  
  782. /**********************************************************************
  783.  *    Function Set_DLOG_Text_Item(), this function sets text boxes in the
  784.  *    selected dialog to the text which is sent to it.
  785.  **********************************************************************/
  786.  
  787. void Set_DLOG_Text_Item(DialogPtr the_dialog, short ID, StringPtr the_text)
  788.     {
  789.     
  790.     Handle        the_handle;
  791.     Rect        the_rect;
  792.     short        item_type;
  793.     
  794.     GetDItem(the_dialog, ID, &item_type, &the_handle, &the_rect);
  795.     SetIText(the_handle, the_text);
  796.     
  797.     }
  798.  
  799.  
  800.  
  801. /**********************************************************************
  802.  *    Function Draw_Dialog(), this function draws the objects in the
  803.  *    main dialog box.
  804.  **********************************************************************/
  805.  
  806. void Draw_Dialog(DialogPtr the_dialog)
  807.     {
  808.     
  809.     Handle        the_handle;
  810.     Rect        the_rect;
  811.     short        item_type;
  812.         
  813.     if(the_dialog==Chng_Dialog)
  814.         {
  815.         TextFont(systemFont);
  816.         TextSize(12);
  817.         TextFace(0);
  818.         
  819.         if(!Multiple_Files)
  820.             {    
  821.             GetDItem(Chng_Dialog, CHNG_ICON, &item_type, &the_handle, &the_rect);
  822.             PlotIconSuite(&the_rect, 0, 0, The_Icons);
  823.             
  824.             Draw_Border(Chng_Dialog, CHNG_CRNT_CREATOR, NO);
  825.             GetDItem(Chng_Dialog, CHNG_CRNT_CREATOR, &item_type, &the_handle, &the_rect);
  826.             MoveTo(the_rect.left+4, the_rect.bottom-7);
  827.             DrawString(C_Type.TEXT);
  828.             
  829.             Draw_Border(Chng_Dialog, CHNG_CRNT_TYPE, NO);
  830.             GetDItem(Chng_Dialog, CHNG_CRNT_TYPE, &item_type, &the_handle, &the_rect);
  831.             MoveTo(the_rect.left+4, the_rect.bottom-7);
  832.             DrawString(F_Type.TEXT);
  833.             }
  834.         
  835.         Draw_Border(Chng_Dialog, CHNG_OK, YES);
  836.         }
  837.     else if(the_dialog==Edit_Dialog)
  838.         {
  839.         Draw_Border(Edit_Dialog, EDIT_CLOSE, YES);
  840.         }
  841.     else if(the_dialog==Auto_Dialog)
  842.         {
  843.         GetDItem(Auto_Dialog, AUTO_DO, &item_type, &the_handle, &the_rect);
  844.         SetCtlValue((ControlHandle)the_handle, (**Global).AutoChange);
  845.         GetDItem(Auto_Dialog, AUTO_QUIT, &item_type, &the_handle, &the_rect);
  846.         SetCtlValue((ControlHandle)the_handle, (**Global).DragQuit);
  847.         
  848.         Draw_Border(Auto_Dialog, AUTO_CLOSE, YES);
  849.         }
  850.         
  851.     }
  852.